package ru.inse.core.domain.dict;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Часть города, для формирования адреса
 * @author evga
 *
 */
public class PlaceType 
{
    static final private Map<Long, PlaceType> map = new LinkedHashMap<Long, PlaceType>();
    static private PlaceType[] array;

    
    static final public PlaceType STREET = new PlaceType(1L, "dict.place.street");    //Улица
    static final public PlaceType TOWNSHIP = new PlaceType(100L, "dict.place.township");    //Район города

    final private long id;
    final private String labelId;

    private PlaceType(long id, String label)
    {
        this.id = id;
        this.labelId = label;
        map.put(id, this);
        array = null;
    }

    public long getId()
    {
        return id;
    }

    public String getLabelId()
    {
        return labelId;
    }
    
    static public PlaceType getById(long code)
    {
        return map.get(code);
    }

    @Override
    public String toString()
    {
        return labelId;
    }
    
    static public PlaceType[] list()
    {
        if (array == null)
        {
            synchronized (PlaceType.class)
            {
                if (array == null)
                {
                    array = new PlaceType[map.size()];
                    int index = 0;
                    for(PlaceType r : map.values())
                    {
                        array[index++] = r;
                    }
                }
            }
            
        }
        return array;
    }

}
